import { CropperComponent } from './../../coms/post-edit-form/cropper/cropper.component';
import { link } from 'fs';
import { MsCodeModalComponent } from './../../coms/ms-code-modal/ms-code-modal.component';
import { PasswordModalComponent } from './../../coms/password-modal/password-modal.component';
import { Router } from '@angular/router';
//tslint:disable
import { AppGlobalService } from 'src/app/shared/service/app-global.service';
import { Injectable } from '@angular/core';
import { ModalController, AlertController, ActionSheetController, Platform } from '@ionic/angular';
import { NestedFormTagComponent } from 'src/app/coms/nested-form-tag/nested-form-tag.component';
import { EventService } from './event.service';
import { ImgSlidePage } from 'src/app/coms/slides-imgage/img-slide.page';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
import { ModalFromCenterEnter, ModalFromCenterLeave, ModalFromRightEnter, ModalFromRightLeave } from 'src/app/utils/transitions';
import { HttpService } from './http.service';
import { SharePageComponent } from 'src/app/coms/share-page/share-page.component';
import { JPush } from '@jiguang-ionic/jpush/ngx';
import { ChatService } from './chatService';
import { IndexedDBService } from './indexed-db.service';
import { isNullOrUndefined } from 'util';
import { ShareService } from './share.service';
import { AppVersion } from '@ionic-native/app-version/ngx';
import { RecommendModalComponent } from 'src/app/coms/recommend-modal/recommend-modal.component';
import { NewInquiryPageModalComponent } from 'src/app/coms/new-inquiry-page-modal/new-inquiry-page-modal.component';
import { CustomPopoverComponent } from 'src/app/coms/custom-popover/custom-popover.component';
import { UrlComponent } from 'src/app/coms/url/url.component';
declare var JGVerificationPlugin;
declare var wx;

@Injectable({
  providedIn: 'root'
})
export class PageModalService {
  shareData: any;
  modalIdArray: any = [];
  xiaomiModels = new Set(["MI-ONE PLUS", "MI-ONE C1", "MI-ONE", "2012051", "2012053", "2012052", "2012061", "2012062", "2013012", "2013021", "2012121", "2013061", "2013062", "2013063", "2014215", "2014218", "2014216", "2014719", "2014716", "2014726", "2015015", "2015561", "2015562", "2015911", "2015105", "2015201", "2015628", "2015711", "2016070", "2016089", "MDE2", "MDT2", "MCE16", "MCT1", "M1804D2SE", "M1804D2ST", "M1804D2SC", "M1803E1A", "M1803E1T", "M1803E1C", "M1807E8S", "M1807E8A", "M1805E2A", "M1808D2TG", "M1808D2TE", "M1808D2TT", "M1808D2TC", "M1902F1G", "M1902F1A", "M1902F1T", "M1902F1C", "M1908F1XE", "M1903F2G", "M1903F2A", "M1903F10G", "M1903F11G", "M1904F3BG", "M2001J2G", "M2001J2I", "M2001J2E", "M2001J2C", "M2001J1G", "M2001J1E", "M2001J1C", "M2002J9G", "M2002J9S", "M2002J9R", "XIG01", "M2002J9E", "M2007J1SC", "M2007J3SY", "M2007J3SP", "M2007J3SG", "M2007J3SI", "M2007J17G", "M2007J17I", "M2102J2SC", "M2011K2G", "M2011K2C", "M2102K1AC", "M2102K1G", "M2102K1C", "M2101K9G", "M2101K9C", "M2101K9R", "M2101K9AG", "M2101K9AI", "2109119DG", "2109119DI", "2107119DC", "M2012K11G", "M2012K11AI", "M2012K11I", "21081111RG", "2107113SG", "2107113SI", "2107113SR", "21091116I", "21091116UI", "2201123G", "2201123C", "2112123AG", "2112123AC", "2201122G", "2201122C", "2207122MC", "2203129G", "2203129I", "2206123SC", "2206122SC", "2203121C", "22071212AG", "22081212UG", "22081212R", "22200414R", "A201XM", "2211133G", "2211133C", "2210132G", "2210132C", "2304FPN6DG", "2304FPN6DC", "2210129SG", "2306EPN60G", "2306EPN60R", "XIG04", "23078PND5G", "23088PND5R", "A301XM", "23127PN0CG", "23127PN0CC", "23116PN5BC", "2311BPN23C", "24030PN60G", "24031PN0DC", "24053PY09I", "2406APNFAG", "XIG06", "2407FPN8EG", "2407FPN8ER", "A402XM", "2015011", "2014616", "2014619", "2014618", "2014617", "2015021", "2015022", "2015501", "2015213", "2015211", "2015212", "MCE8", "MCT8", "M1910F4G", "M1910F4S", "M2002F4LG", "2016080", "MDE5", "MDT5", "MDE5S", "M1803D5XA", "M1803D5XE", "M1803D5XT", "M1803D5XC", "M1810E5A", "M1810E5E", "M1810E5GG", "2106118C", "M2011J18C", "22061218C", "2308CPXD0C", "24072PX77C", "2405CPX3DG", "2405CPX3DC", "2016002", "2016001", "2016007", "MDE40", "MDT4", "MDI40", "M1804E4A", "M1804E4T", "M1804E4C", "M1904F3BC", "M1904F3BT", "M1906F9SC", "M1910F4E", "2109119BC", "2109119BC", "2209129SC", "23046PNC9C", "24053PY09C", "M1901F9E", "M1901F9T", "MDG2", "MDI2", "M1804D2SG", "M1804D2SI", "M1805D1SG", "M1906F9SH", "M1906F9SI", "2013022", "2013023", "2013029", "2013028", "2014011", "2014501", "2014813", "2014112", "2014817", "2014818", "2014819", "2014811", "2014812", "2014821", "2014502", "2014512", "2014055", "2014816", "2015816", "2015811", "2015815", "2015812", "2015810", "2015817", "2015819", "2015818", "2016031", "2016037", "2016032", "2016030", "2016036", "2016035", "2016033", "2016090", "2016060", "2016117", "2016116", "2016111", "2016112", "MAG138", "MAI132", "MAE136", "MAT136", "MDG1", "MDI1", "MDE1", "MDT1", "MEG7", "MEE7", "MET7", "MCG3B", "MCI3B", "MCE3B", "MCT3B", "M1804C3DG", "M1804C3DH", "M1804C3DI", "M1804C3DE", "M1804C3DT", "M1804C3DC", "M1805D1SI", "M1805D1SE", "M1805D1ST", "M1805D1SC", "M1804C3CG M1804C3CH", "M1804C3CI", "M1804C3CE", "M1804C3CT", "M1804C3CC", "M1810F6LG", "M1810F6LH", "M1810F6LI", "M1810F6LE", "M1810F6LT", "M1903C3EG", "M1903C3EH", "M1903C3EI", "M1903C3EE", "M1903C3ET", "M1903C3EC", "M1908C3IG", "M1908C3IH", "M1908C3II", "M1908C3IE", "M1908C3IC", "M1908C3KG", "M1908C3KH", "M1908C3KI", "M1908C3KE", "M2001C3K3I", "M2004J19G", "M2004J19I", "M2004J19C", "M2004J19AG", "M2006C3LG", "M2006C3LVG", "M2006C3LI", "M2006C3LII", "M2006C3LC", "M2006C3MG", "M2006C3MT", "M2006C3MNG", "M2006C3MII", "M2010J19SG", "M2010J19SI", "M2010J19SR", "M2010J19ST", "M2010J19SY", "M2010J19SL", "21061119AG", "21061119AL", "21061119BI", "21061119DG", "21121119SG", "21121119VL", "22011119TI", "22011119UY", "22041219G", "22041219I", "22041219NY", "220333QAG", "220333QBI", "220333QNY", "220333QL", "220233L2G", "220233L2I", "220233L2C", "22071219AI", "23053RN02A", "23053RN02I", "23053RN02L", "23053RN02Y", "23076RN8DY", "23077RABDC", "23076RA4BR", "XIG03", "A401XM", "23076RN4BI", "23076RA4BC", "22120RN86G", "22120RN86H", "22120RN86I", "22120RN86C", "2212ARNC4L", "22126RN91Y", "2404ARN45A", "2404ARN45I", "24049RN28L", "24040RN64Y", "2406ERN9CC", "2406ERN9CI", "23106RN0DA", "2311DRN14I", "23100RN82L", "23108RN04Y", "23124RN87G", "23124RN87I", "23124RN87C", "2014018", "2013121", "2014017", "2013122", "2014715", "2014712", "2014022", "2014021", "2014912", "2014915", "2014911", "2014916", "2014910", "2015051", "2015712", "2015052", "2015055", "2015056", "2015617", "2015611", "2015116", "2015112", "2015115", "2015161", "2016050", "2016051", "2016100", "2016102", "2016101", "2016130", "MBE6A5", "MBT6A5", "MEI7", "M1803E7SG", "M1803E7SH", "MEI7S", "MEE7S", "MET7S", "MEC7S", "MDG6", "MDI6", "MDE6", "MDT6", "MDG6S", "MDI6S", "MDE6S", "MDT6S", "M1806E7TG", "M1806E7TH", "M1806E7TI", "M1901F7G", "M1901F7H", "M1901F7I", "M1901F7E", "M1901F7T", "M1901F7C", "M1901F7S", "M1901F7BE", "M1908C3JG", "M1908C3JH", "M1908C3JI", "M1908C3JE", "M1908C3JC", "M1908C3XG", "M1908C3JGG", "M1906G7G", "M1906G7E", "M1906G7T", "M1906G7I", "M2003J15SS", "M2003J15SI", "M2003J15SG", "M2010J19SC", "M2007J22C", "M2007J22G", "M2007J22R", "A001XM", "M2003J6A1G", "M2003J6A1R", "M2003J6A1I", "M2003J6B1I", "M2003J6B2G", "M2007J17C", "M2101K7AG", "M2101K7AI", "M2101K7BG", "M2101K7BI", "M2101K7BNY", "M2101K7BL", "M2103K19G", "M2103K19Y", "M2103K19I", "M2103K19C", "M2104K19J", "XIG02", "22021119KR", "A101XM", "M2101K6G", "M2101K6T", "M2101K6R", "M2101K6P", "M2101K6I", "M2104K10AC", "2109106A1I", "21121119SC", "2201117TG", "2201117TI", "2201117TL", "2201117TY", "21091116AI", "21091116AC", "22041219C", "2201117SG", "2201117SI", "2201117SL", "2201117SY", "22087RA4DI", "22031116BG", "2201116TG", "2201116TI", "2201116SG", "2201116SR", "2201116SC", "2201116SI", "21091116C", "21091116UG", "21091116UC", "22041216C", "22041216UC", "22095RA98C", "23021RAAEG", "23027RAD4I", "23028RA60L", "23021RAA2Y", "22111317G", "22111317I", "22101317C", "23076RA4BC", "2303CRA44A", "2303ERA42L", "23030RAC7Y", "2209116AG", "22101316G", "22101316I", "22101316C", "22101316UG", "22101316UP", "22101316UCP", "22101316UC", "22101320C", "23054RA19C", "23049RAD8C", "23129RAA4G", "23129RA5FL", "23124RA7EO", "2312DRAABG", "2312DRAABI", "2312DRAABC", "23117RA68G", "2312DRA50G", "2312DRA50I", "2312DRA50C", "2312CRAD3C", "XIG05", "23090RA98G", "23090RA98I", "23090RA98C", "24040RA98R", "2406ERN9CC", "2311FRAFDC", "M2004J7AC", "M2004J7BC", "M2003J15SC", "24069RA21C", "M1903F10A", "M1903F10C", "M1903F10I", "M1903F11A", "M1903F11C", "M1903F11I", "M1903F11A", "M2001G7AE", "M2001G7AC", "M2001G7AC", "M1912G7BE", "M1912G7BC", "M2001J11C", "M2001J11C", "M2001J11E", "M2006J10C", "M2007J3SC", "M2012K11AC", "M2012K11C", "M2012K10C", "22021211RC", "22041211AC", "22011211C", "21121210C", "22081212C", "22041216I", "23013RK75C", "22127RK46C", "22122RK93C", "23078RKD5C", "2407FRK8EC", "23113RKC6C", "23117RK66C", "2311DRK48C", "2016020", "2016021", "M1803E6G", "M1803E6H", "M1803E6I", "M1803E6E", "M1803E6T", "M1803E6C", "M1810F6G", "M1810F6I", "M1903C3GG", "M1903C3GH", "M1903C3GI", "220733SG", "220733SH", "220733SI", "220733SL", "220733SFG", "220733SFH", "220743FI", "23028RN4DG", "23028RN4DH", "23028RN4DI", "23026RN54G", "23028RNCAG", "23028RNCAH", "23028RNCAI", "23129RN51X", "23129RN51H", "2312CRNCCL", "24048RN6CG", "24048RN6CI", "24044RN32L", "M1805E10A", "M2004J11G", "M2012K11AG", "M2104K10I", "22021211RG", "22021211RI", "21121210G", "23049PCD8G", "23049PCD8I", "23013PC75G", "24069PC21G", "24069PC21I", "23113RKC6G", "M1912G7BI", "M2007J20CI", "M2007J20CG", "M2007J20CT", "M2102J20SG", "M2102J20SI", "21061110AG", "2201116PG", "2201116PI", "22041216G", "22041216UG", "22111317PG", "22111317PI", "22101320G", "22101320I", "23122PCD1G", "23122PCD1I", "2311DRK48G", "2311DRK48I", "2312FRAFDI", "M2004J19PI", "M2003J6CI", "M2010J19CG", "M2010J19CT", "M2010J19CI", "M2103K19PG", "M2103K19PY", "M2103K19PI", "22041219PG", "22041219PI", "2201117PG", "2201117PI", "21091116AG", "22031116AI", "22071219CG", "22071219CI", "2207117BPG", "2404APC5FG", "2404APC5FI", "23128PC33I", "24066PC95I", "2312FPCA6G", "23076PC4BI", "M2006C3MI", "211033MI", "220333QPG", "220333QPI", "220733SPH", "220733SPI", "2305EPCC4G", "2302EPCC4H", "2302EPCC4I", "22127PC95G", "22127PC95H", "22127PC95I", "2312BPC51X", "2312BPC51H", "2310FPCA4G", "2310FPCA4I", "A0101", "2015716", "MCE91", "M1806D9W", "M1806D9E", "M1806D9PE", "21051182G", "21051182C", "M2105K81AC", "M2105K81C", "22081281AC", "23043RP34G", "23043RP34I", "23043RP34C", "23046RP50C", "2307BRPDCC", "24018RPACG", "24018RPACC", "22081283G", "22081283C", "23073RPBFG", "23073RPBFC", "23073RPBFL", "2405CRPFDG", "2405CRPFDC", "2405CRPFDI", "2405CRPFDL", "24074RPD2G", "24074RPD2C", "2405CPCFBG", "FYJ01QP", "21051191C"]);
  vivoModels = new Set(["V1821A", "V1821T", "V1923A", "V1923T", "V1924A", "V1924T", "V1950A", "V1814A", "V1814T", "V1809A", "V1809T", "V1816A", "V1816T", "V1829A", "V1829T", "V1838A", "V1838T", "V1836A", "V1836T", "V1938CA", "V1938CT", "V1938A", "V1938T", "V2001A", "V2005A", "V2011A", "V2046A", "V2059A", "V2085A", "V2047A", "V2120A", "V2056A", "V2056A", "V2133A", "V2132A", "V2134A", "V2145A", "V2178A", "V2170A", "V2183A", "V2185A", "V2186A", "V2229A", "V2241A", "V2241HA", "V2242A", "V2227A", "V2266A", "V2256A", "V2309A", "V2324A", "V2303A", "V2337A", "V2359A", "V2324HA", "V2366GA", "V2366HA", "V1831A", "V1831T", "V1832A", "V1832T", "V1932A", "V1932T", "V1962A", "V2020A", "V2020CA", "V2080A", "V2031A", "V2031EA", "V2072A", "V2048A", "V2121A", "V2121A", "V2130A", "V2162A", "V2163A", "V2203A", "V2207A", "V2190A", "V2244A", "V2245A", "V2239A", "V2283A", "V2282A", "V2284A", "V2285A", "V2323A", "V2344A", "V2334A", "V2364A", "V2362A", "V1901A", "V1901T", "V1930A", "V1930T", "V1901A", "V1901T", "V1934A", "V1934T", "V1913A", "V1913T", "V1945A", "V1945T", "V2140A", "V2168A", "V2180A", "V2236A", "V2317A", "V2034A", "V2036A", "V2099A", "V2066A", "V2066BA", "V2054A", "V2068A", "V2068A", "V2054A", "V2158A", "V2168A", "V2180A", "V2166A", "V2166A", "V2317A", "V2230A", "V2279A", "V2318A", "V2327A", "V1965A", "V2023EA", "V2002A", "V2057A", "V2054A", "V2166A", "V2111A", "V2069A", "V2123A", "V2069A", "V2230A", "V2045A", "V2164A", "V2279A", "V2002A", "V2002A", "V1731CA", "V2102A", "V2164A", "V1731CA", "V2031A", "V2164PA", "V2009A", "V2069BA", "V2156A", "V2156FA", "V2219A", "V2166BA", "V2278A", "V2271A", "V2279A", "V2312BA", "V1732A", "V1732T", "V1732A", "V1732T", "V1730EA", "V1818CA", "V1818CT", "V1818A", "V1818T", "V1818BA", "V1818CA", "V1818CT", "V1818CA", "V1818CT", "V1813A", "V1813T", "V2313A", "V2314DA", "V2279A", "V2312BA", "V2343A", "V2361GA", "V2353DA", "V2354A", "V2115A", "V2123A", "V2188A", "V1801A0", "V1730DA", "V1730DT", "V1730EA", "V1813BA", "V1813BT", "V1813A", "V1813T", "V1813A", "V1813T", "V1730GA", "V1921A", "V1921T", "V1911A", "V1919A", "V1990A", "V1941A", "V1941T", "V1963A", "V1818A", "V1941A", "V1941T", "V1928A", "V1928T", "V1962BA", "V2318A", "V1824BA", "V1824A", "V1922A", "V1922T", "V1916A", "V1916T", "V1955A", "V2024A", "V2025A", "V2049A", "V2136A", "V2141A", "V2171A", "V2172A", "V2217A", "V2218A", "V2243A", "V2254A", "V2304A", "V2307A", "V2329A", "V1914A", "V1914T", "V1936A", "V1936T", "V1936AL", "V1936TL", "V1981A", "V2055A", "V2118A", "V2154A", "V2157A", "V2196A", "V2199A", "V2231A", "V2232A", "V2238A", "V2301A", "V2302A", "V2338A", "V2339A", "V2339FA", "V2403A", "V1986A", "V2012A", "V2073A", "V2148A", "V2131A", "V2220A", "V2164KA", "V2270A", "V2272A", "V2230EA", "V2314A", "V2312A", "V2361A", "V2352A", "V2353A", "V2023A", "V2065A", "V2061A", "V2106A", "V2143A", "V2165A", "V2180GA", "V2197A", "PA2170", "PA2373", "PA2353", "PA2455", "PA2473", "iPA2375", "iPA2451", "iPA2453", "iPA2475"]);
  meizuModels = new Set(["M8", "M8SE", "M9", "M030", "M031", "M032", "M040", "M045", "M351", "M353", "M355", "M356", "M460H", "M460", "M460A", "M461", "M462H", "M462", "M462U", "M575H", "M575", "M575M", "M575U", "M685H", "M685Q", "M685M", "M685U", "M685C", "M576H", "M576", "M576U", "M570H", "M570Q", "M570M", "M570C", "M570Q-S", "M686H", "M686", "M686G", "M792H", "M792Q-L", "M792M-L", "M792C-L", "M792Q", "M792C", "M793H", "M793Q", "M881H", "M881Q", "M881M", "M891H", "M891Q", "M871H", "M871Q", "M882H", "M882Q", "M892Q", "M872H", "M872Q", "M971H", "M971Q", "M926H", "M926Q", "M973Q", "M928Q", "M081Q", "M081M", "M091Q", "M091M", "M181Q", "M191Q", "M172Q", "M182Q", "M192Q", "M381Q", "M391Q", "M392Q", "M461Q", "M461H", "M481Q", "M468Q", "M468H", "M463H", "M463M", "M463U", "M463C", "M571H", "M571", "M571M", "M571U", "M571C", "M681H", "L681H", "M681Q", "L681Q", "M681M", "L681M", "M681C", "L681C", "M621H", "M621Q", "M621M", "M621C", "M621C-S", "M721H", "M721Q", "M721M", "M721C", "M822H", "M822Q", "M923H", "M923Q", "A680H", "A680Q", "A680M", "M741A", "M741Y", "M851Q", "M851M", "M852H", "M852Q", "M682Q", "M465M", "M465A", "M578H", "M578", "M578A", "M578M", "M578MA", "M578U", "M578C", "M578CE", "M578CA", "M688Q", "M688M", "M688U", "M688C", "Y685H", "Y685Q", "Y685M", "Y685C", "M611H", "M611A", "M611Y", "M611D", "M612H", "M612Q", "M612M", "M612C", "M710H", "M710M", "M711H", "M711Q", "M711M", "M711C", "M712H", "M712Q", "M712Q-B", "M712M", "M712C", "M811H", "M811Q", "M813H", "M813Q", "M816H", "M816Q", "M810H", "M918H", "M2110", "M2111", "S685H", "S685Q", "S685M", "S685C", "M57A", "M57AM", "M57AU", "M57AC", "U680H", "U680A", "U680Y", "U680D", "U685H", "U685Q", "U685M", "U685C", "M818H", "M819H", "M481S"]);
  oppoModels = new Set(["PAFM00", "PAFT00", "PAHM00", "PAFT10", "PDEM10", "PDET10", "PDEM30", "PEDM00", "PEEM00", "PEEM00", "PFFM10", "PFEM10", "PFFM20", "PGFM10", "PGEM10", "PHZ110", "PHY110", "PHY120", "PEUM00", "PGU110", "PGT110", "PHN110", "PHT110", "PCAM00", "PCAT00", "PCCM00", "PCCT00", "PCDM10", "PCDT10", "PCKM00", "PCKT00", "PCKM80", "PCKT80", "PDCM00", "PDCT00", "PCRM00", "PCRT00", "PCLM50", "PCRT01", "PDPM00", "PDPT00", "PDNM00", "PDNT00", "PEAM00", "PEAT00", "PEGM00", "PEGT00", "PEGM10", "PEGT10", "PDSM00", "PDST00", "PDRM00", "PEQM00", "PEPM00", "PENM00", "PFJM10", "PFDM00", "PFCM00", "PGBM10", "PGAM10", "PFZM10", "PHM110", "PGX110", "PGW110", "PHW110", "PHV110", "PHU110", "PJH110", "PJJ110", "PJV110", "PJW110", "PCLM10", "PDHM00", "PACM00", "PACT00", "PAAM00", "PAAT00", "PBCM10", "PBCT10", "PBEM00", "PBET00", "PBDM00", "PBDT00", "PADM00", "PADT00", "PBAM00", "PBBM30", "PBAT00", "PBBT30", "PBFM00", "PBFT00", "PBBM00", "PBBT00", "PCDM00", "PCDT00", "PDBM00", "PDBT00", "PCAM10", "PCAT10", "PCEM00", "PCET00", "PCHM10", "PCHT10", "PCHM30", "PCHT30", "PCHM00", "PCHT00", "PDVM00", "PDVM00", "PEFM00", "PESM10", "PDAM10", "PDAT10", "PECM20", "PECM30", "PECT30", "PEMM00", "PEMM20", "PEMT00", "PEMT20", "PEMM00", "PFVM10", "PFTM20", "PFTM20", "PHJ110", "PHJ110", "PDYM20", "PDYT20", "PDYM10", "PCPM00", "PCPT00", "PDKM00", "PDKT00", "PEHM00", "PEHT00", "PFGM00", "PELM00", "PFUM10", "PHA120", "PFTM10", "PHS110", "PHQ110", "PHJ110", "PJB110", "PJU110", "PJS110", "PJG110", "PKA110", "PKD110", "PKD120", "PKD130", "PJY110", "PBCM30", "PCGM00", "PCGT00", "PCNM00", "PCNT00", "PCLM50", "PERM00", "PEXM00", "PERM10", "PEYM00", "PGCM10", "PGJM10", "PGIM10", "PGGM10", "PJC110", "PHF110", "PJR110", "PJT110", "OPD2101", "OPD2102", "OPD2201", "OPD2301", "OB19B1", "OB19B3", "OB19O0", "OB19O1", "OB19O2", "OBB211", "OBB213", "OR19R1", "OWW206", "OWW208", "OW19W1", "OW19W2", "OW19W3", "OWW202", "OW20W1", "OW20W2", "OW20W3", "OWW212", "OWW211", "OWW213", "OWW221", "OWW231"]);
  constructor(
    public modalController: ModalController,
    public alertCtrl: AlertController,
    public actionSheetCtrl: ActionSheetController,
    public eventService: EventService,
    public http: HttpService,
    public appGlobalService: AppGlobalService,
    public router: Router,
    private iab: InAppBrowser,
    private platform: Platform,
    public indexedDBService: IndexedDBService,
    public shareService: ShareService,
    public chatService: ChatService,
    private appVersion: AppVersion,
    public jPush: JPush,
    public alertController: AlertController,

  ) {
    if (this.eventService.eventEmit.listenerCount('openPage') > 0) {
      this.eventService.eventEmit.removeListener('openPage');
    }
    this.eventService.eventEmit.on('openPage', res => {
      this.openPage(JSON.parse(res));
    })
  }
  setLink(link) {
    window["otherButton"] = link;
  }
  setWechatLink(link) {
    window["wxlinkButton"] = link;
  }
  // 打开图片展示框，滑动展示
  async openImage(index, images, download?) {
    const urlArray = [];
    images.forEach(element => {
      if (element.imageUrl) {
        urlArray.push(element.imageUrl);
      } if (element.path) {
        urlArray.push(element.path);
      }
      else {
        urlArray.push(element.value);
      }

    });
    const value = { img: urlArray, index: index + 1, download };
    const modal = await this.modalController.create({
      component: ImgSlidePage,
      componentProps: { value: JSON.stringify(value) }
    });
    return await modal.present();
  }
  // 数组中是 url 
  async openImage_url(index, images, download?) {
    const value = { img: images, index: index + 1, download };
    const modal = await this.modalController.create({
      component: ImgSlidePage,
      componentProps: { value: JSON.stringify(value) }
    });
    return await modal.present();
  }

  //  
  async openImageToCropper(data, callbackFunc?: Function) {

    const modal = await this.modalController.create({
      component: CropperComponent,
      componentProps: { data }
    });
    await modal.present();
    await modal.onDidDismiss().then(data => {
      if (data && data.data) {
        console.log('OK');
        callbackFunc(data.data);
      } else {
        console.log('CANCEL');
        callbackFunc(false);
      }
    });
  }

  async openPasswordModal(title?, callbackFunc?: Function) {
    const modalId = this.addModeId()
    const modal = await this.modalController.create({
      showBackdrop: true,
      component: PasswordModalComponent,
      cssClass: 'auto-modal',
      componentProps: {
        cssStyle: '', cssClass: 'auto-modal', tags: [{ style: 'password' }]
      },
      id: modalId
    });
    await modal.present();
    await modal.onDidDismiss().then(data => {
      this.removeModeId(modalId);
      if (data && data.data && data.data.data) {
        console.log('OK');
        callbackFunc(data.data.data);
      } else {
        console.log('CANCEL');
        callbackFunc(false);
      }
    });
  }

  async openMsCodeModal(item?, callbackFunc?: Function) {
    const modalId = this.addModeId();
    const modal = await this.modalController.create({
      showBackdrop: true,
      component: MsCodeModalComponent,
      cssClass: 'auto-modal',
      componentProps: {
        cssStyle: '', cssClass: 'bottom', item
      },
      id: modalId
    });
    await modal.present();
    await modal.onDidDismiss().then(data => {
      this.removeModeId(modalId)
      if (data && data.data && data.data.data) {
        console.log('OK');
        if ((typeof callbackFunc) !== 'undefined') {
          callbackFunc(data.data.data);
        }
      } else {
        console.log('CANCEL');
        if ((typeof callbackFunc) !== 'undefined') {
          callbackFunc(false);
        }
      }
    });
  }

  async openPage(link, title?, callbackFunc?: Function) {
    try {
      // 2024.09.19 新增联调页面跳转 华为设备
      // 从localStorage获取huawei的值，并判断其是否有效  
      const huaweiValid = localStorage.getItem('huawei') && localStorage.getItem('huawei') !== 'false';
      // 如果huawei有效，且link对象及其相关属性存在
      if (huaweiValid
        && link
        && link.params
        && link.params.allowedTrials !== undefined
        && link.params.oldAccount === 'false') {
        // 根据allowedTrials的值决定是失败页面还是成功页面  
        const allowedTrials = link.params.allowedTrials;
        if (allowedTrials === '0' || allowedTrials === '' || allowedTrials === 'null') {
          // 处理失败页面的逻辑  
          const numericValue = Number(link.params.checkHuaweiFailPage);
          const isValidNumber = !isNaN(numericValue) && isFinite(numericValue); // 检查是否是有效数字且不是Infinity          
          if (isValidNumber && link.params.checkHuaweiFailPage !== undefined) {
            link.target = link.params.checkHuaweiFailPage;
            link.type = link.params.failPageType || 'pageModal';
            // 设置默认的modalCss，如果未定义  
            if (link.params.modalCss === undefined) {
              link.params.modalCss = 'auto-modal';
            }
          }
        } else {
          const numericValue = Number(link.params.checkHuaweiSuccessPage);
          const isValidNumber = !isNaN(numericValue) && isFinite(numericValue); // 检查是否是有效数字且不是Infinity
          // 处理成功页面的逻辑  
          if (isValidNumber && link.params.checkHuaweiSuccessPage !== undefined) {
            link.target = link.params.checkHuaweiSuccessPage;
            link.type = link.params.successPageType || 'page';
            // 如果modalCss已定义，则删除它  
            if (link.params.modalCss !== undefined) {
              delete link.params.modalCss;
            }
          }
        }
      }


      if (link && link.params && link.params.closeAllModal !== undefined) {
        this.closeAllModal();
      } else if (link && link.params && link.params.closeModal !== undefined) {
        try {
          const modal = this.modalController.getTop();
          if (modal) { this.modalController.dismiss({ data: true }) }
        } catch (error) {
        }
      }
      if (!link) {
        return;
      }
      // 如果跳转页面带了经纬度则需要使用手机定位存储的经纬度
      if (link.params !== undefined
        && link.params.latitude
        && link.params.longitude
        && link.params.disablePoints === undefined
      ) {

        if (link.params.useParamsPoints === undefined) {
          if (localStorage.getItem("position")) {
            let position = JSON.parse(localStorage.getItem("position"));
            if (link.params.useCurrentPosition !== undefined) {
              // 2023-10-18 当用户配置了使用当前定位信息则使用最新的定位
              position = JSON.parse(localStorage.getItem("currentCityPosition"));
              console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + ' refreshLocationStore... for position 1  ', '  	   ');
            }
            if (position.center && position.center.lat && position.center.lng) {
              link.params.latitude = position.center.lat;
              link.params.longitude = position.center.lng;

              console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + ' refreshLocationStore... for position 2   ', '  	   ');
            }


            if (position.center.name && position.center.code) {
              link.params.cityName = position.center.name;
              link.params.cityCode = position.center.code;
            }
          }
        }
      }
      if (link.type === 'disable') {
        return
      } else if (link && link.params !== undefined && link.params.disableCLick !== undefined) {
        return;
      } else if (link.params !== undefined && link.params.oneLogin !== undefined && link.params.passwordLogin !== undefined && link.params.visitor === undefined && localStorage.getItem('loginStatus') !== 'true') {
        // 包含登录参数 先登录
        this.toLogin(link, title, callbackFunc);
      } else if (link.type === 'tip' && link.params.message) {
        this.appGlobalService.showToast(link.params.message, 1500, 'top');
      } else if (link.type === 'page' || link.type === 'submitLink') {
        const pageParams = {
          pageId: link.target,
          params: link.params ? link.params : {},
          sessionId: localStorage.getItem('sessionId')
        };
        if (pageParams.params.skipWeb && pageParams.params.skipWeb.length > 0) {
          if (pageParams.params.title && pageParams.params.title.length > 0) {
            this.appGlobalService.openUrl(pageParams.params.title, pageParams.params.skipWeb);
          } else {
            this.appGlobalService.openUrl(title, pageParams.params.skipWeb);
          }

        } else {
          this.appGlobalService.goToForward(pageParams);
        }
      } else if (link.type === 'pageModal' || link.type === 'modal' || link.type === 'model' || link.type === 'pageModalStyle') {
        if (link.modalCss) {
        } else if (link.params && link.params.modalCss) {
          link.modalCss = link.params.modalCss;
        }
        const params = {
          sessionId: localStorage.getItem("sessionId"),
          pageId: link.target ? link.target : link.pageId,
          params: link.params ? link.params : {}
        };
        let modal: any;
        let modalId = this.addModeId();
        // 2023年10月20日新增样式
        if (link.params.importantCssStyle !== undefined) {
          link.params.cssStyle = link.params.importantCssStyle;
        }
        if (link.modalCss && link.modalCss !== 'video-modal' && link.modalCss !== 'bottom') {
          // login_page successlink 通过手机号码拿数据
          if (link && link.params && link.params.needGetPageBeforeShowModal) {
            let tempTags = [];
            let pageData;
            this.http.post('application/page', params, async res => {
              pageData = JSON.parse(res.script);
              tempTags = pageData.views === undefined ? pageData.tags : pageData.views[0].tags;
              if (tempTags.length > 0) {
                const modalId1 = this.addModeId()
                let modal1 = await this.modalController.create({
                  showBackdrop: true,
                  component: NestedFormTagComponent,
                  cssClass: 'auto-modal',
                  componentProps: {
                    cssStyle: link.cssStyle ? link.cssStyle : link.params.cssStyle,
                    cssClass: link.modalCss,
                    pageData: pageData
                  },
                  id: modalId1
                });
                await modal1.present();
                await modal1.onDidDismiss().then(data => {
                  this.removeModeId(modalId1);
                  if (data && data.data && data.data.data) {
                    console.log('OK1');
                    if ((typeof callbackFunc) !== 'undefined') {
                      callbackFunc(data.data.data);
                    }

                  } else if (data && data.data && data.data.filter) {
                    console.log('filter1');
                    if ((typeof callbackFunc) !== 'undefined') {
                      callbackFunc(data.data);
                    }
                  } else {
                    console.log('CANCEL1');
                    if ((typeof callbackFunc) !== 'undefined') {
                      callbackFunc(false);
                    }
                  }
                });
              }
            });
          } else {
            if (link.modalCss === 'customHeightPage') {
              modal = await this.modalController.create({
                showBackdrop: true,
                component: NestedFormTagComponent,
                cssClass: 'auto-modal',
                componentProps: {
                  cssStyle: link.cssStyle ? link.cssStyle : ((link.params && link.params.cssStyle) ? link.params.cssStyle : ""),
                  cssClass: link.modalCss,
                  pageParams: params
                },
                id: modalId
              });
            } else if (link.modalCss === 'customModalTag') {
              const params = {
                sessionId: localStorage.getItem("sessionId"),
                pageId: link.target,
                params: link.params
              };
              this.http.post('application/page', params, res => {
                console.log(JSON.parse(res.script));
                const tags = JSON.parse(res.script).views[0].tags;
                const len = tags.length;
                for (let i = 0; i < len; i++) {
                  const tmpTag = tags[i];
                  const tmpStyle = tags[i].style;
                  if (tmpStyle === 'appVipPopupTag') {
                    this.showRecommenMessageVip(tmpTag.data);
                    break;
                  } else if (tmpStyle === 'tipsDivTag') {
                    this.showRecommenTip(tmpTag);
                    break;
                  } else if (tmpStyle === 'inquiry-page-style') {
                    this.presentAlertDialogConfirm(tmpTag);
                    break;
                  }
                }
              });
            } else if (link.params && link.params.showBackdrop !== undefined && link.params.showBackdrop === 'false') {
              modal = await this.modalController.create({
                showBackdrop: false,
                component: NestedFormTagComponent,
                cssClass: 'auto-modal',
                componentProps: {
                  cssStyle: link.cssStyle ? link.cssStyle : link.params.cssStyle,
                  cssClass: link.modalCss,
                  pageParams: params
                },
                id: modalId,
                enterAnimation: ModalFromCenterEnter,
                leaveAnimation: ModalFromCenterLeave
              });
            } else {
              modal = await this.modalController.create({
                showBackdrop: true,
                component: NestedFormTagComponent,
                cssClass: 'auto-modal',
                componentProps: {
                  cssStyle: link.cssStyle ? link.cssStyle : link.params.cssStyle,
                  cssClass: link.modalCss,
                  pageParams: params
                },
                id: modalId,
                enterAnimation: ModalFromCenterEnter,
                leaveAnimation: ModalFromCenterLeave
              });
            }
          }
        } else if (link && link.params && link.params.showAnimation === 'ModalFromRightEnter') {
          modal = await this.modalController.create({
            showBackdrop: true,
            component: NestedFormTagComponent,
            cssClass: 'auto-modal',
            componentProps: {
              cssStyle: link.cssStyle ? link.cssStyle : ((link.params && link.params.cssStyle) ? link.params.cssStyle : ""),
              cssClass: link.modalCss,
              pageParams: params
            },
            id: modalId,
            enterAnimation: ModalFromRightEnter,
            leaveAnimation: ModalFromRightLeave
          });
        } else {
          // login_page successlink 通过手机号码拿数据
          if (link && link.params && link.params.needGetPageBeforeShowModal) {
            this.http.post('application/page', params, async res => {
              const pageData = JSON.parse(res.script);
              const tempTags = pageData.views === undefined ? pageData.tags : pageData.views[0].tags;
              if (tempTags.length > 0) {
                const modalId1 = this.addModeId();
                let modal1 = await this.modalController.create({
                  showBackdrop: true,
                  component: NestedFormTagComponent,
                  cssClass: 'auto-modal',
                  componentProps: {
                    cssStyle: link.cssStyle ? link.cssStyle : link.params.cssStyle,
                    cssClass: link.modalCss,
                    pageData: pageData
                  },
                  id: modalId1
                });

                await modal1.present();
                await modal1.onDidDismiss().then(data => {
                  this.removeModeId(modalId1);
                  if (data && data.data && data.data.data) {
                    console.log('OK1');
                    if ((typeof callbackFunc) !== 'undefined') {
                      callbackFunc(data.data.data);
                    }
                  } else if (data && data.data && data.data.filter) {
                    console.log('filter1');
                    if ((typeof callbackFunc) !== 'undefined') {
                      callbackFunc(data.data);
                    }
                  } else {
                    console.log('CANCEL1');
                    if ((typeof callbackFunc) !== 'undefined') {
                      callbackFunc(false);
                    }
                  }
                });
              }
              // this.parsePageData(pageData);
            });
          } else {

            modal = await this.modalController.create({
              showBackdrop: true,
              component: NestedFormTagComponent,
              cssClass: 'auto-modal',
              componentProps: {
                cssStyle: link.cssStyle ? link.cssStyle : ((link.params && link.params.cssStyle) ? link.params.cssStyle : ""),
                cssClass: link.modalCss,
                pageParams: params
              },
              id: modalId

            });
          }


        }


        await modal.present();
        await modal.onDidDismiss().then(data => {
          this.removeModeId(modalId)
          if (data && data.data && data.data.data) {
            console.log('OK');
            if ((typeof callbackFunc) !== 'undefined') {
              callbackFunc(data.data.data);
            }
          } else if (data && data.data && data.data.filter) {
            console.log('filter');
            if ((typeof callbackFunc) !== 'undefined') {
              callbackFunc(data.data);
            }
          } else {
            console.log('CANCEL');
            if ((typeof callbackFunc) !== 'undefined') {
              callbackFunc(false);
            }
          }
        });
      } else if (link.type === 'view') {
        const pageParams = {
          viewId: link.target,
          params: link.params ? link.params : {},
          sessionId: localStorage.getItem('sessionId')
        };
        this.appGlobalService.goToForward(pageParams);
      } else if (link.type === 'url') {
        if (link.urlLinkTitle) {
          this.appGlobalService.openUrl(link.urlLinkTitle, link.target);
        } else if (link.params && link.params.download) {
          // 2024.10.25 13:56 fixed wx is not undefined !
          if ((typeof wx) !== 'undefined' && link.params.skipCheckWX === undefined) {
            wx.miniProgram.getEnv((res) => {
              if (res.miniprogram) {
                let path = '/pages/download?url=' + encodeURIComponent(link.target)
                wx.miniProgram.navigateTo({ url: path });
              }
            });
          } else if (localStorage.getItem('platform') === 'ios') {
            this.iab.create(link.target, '_system');
          } else {
            window.open(link.target, "_system");
          }
        } else {
          this.appGlobalService.openUrl(title, link.target);
        }

      } else if (link.type === 'chat') {
        try {
          const modal = this.modalController.getTop();
          if (modal !== undefined && (!link.params.modalRetain || link.params.modalRetain !== 'true')) {
            (await modal).dismiss('success');
          }
        } catch (error) {
        }
        const paramsToCheck = [
          { key: 'chatUserId', storageKey: 'enterChatRoomByUserId' },
          { key: 'chatId', storageKey: 'enterChatRoomByUserId' },
          { key: 'chatMobile', storageKey: 'enterChatRoomByUserId' },
          { key: 'userId', storageKey: 'enterChatRoomByUserId' }
        ];

        let isValid = paramsToCheck.some(param => link.params[param.key] && link.params[param.key] !== '');
        if (isValid) {
          localStorage.setItem('enterChatRoomByUserId', '1');
          const userId = link.params.chatId || link.params.chatUserId || link.params.chatMobile || link.params.userId;
          this.eventService.eventEmit.emit('enterChatRoomByUserId',
            {
              userId: userId,
              fromFriendList: true,
              friendName: this.chatService.nickNames[userId],
              friendAvatar: this.chatService.getAvatar(userId)
            });
        } else {
          this.appGlobalService.consoleLog('chatId没有配置！  ', '  	   ');
          this.appGlobalService.showToast('网络繁忙，请稍后重试！', 2000, 'middle');
        }
      } else if (link.type === 'searchInput') {
        // 全局搜索 searchInput searchType : 1
        localStorage.removeItem("searchParams");
        localStorage.removeItem("invitationArr");

        const searchPath = "/navSearch";
        let obj = { searchType: "1", link };
        if (link.params) {
          if (link.params.searchType) {
            obj = { searchType: link.params.searchType, link }
          }
        }

        this.router.navigate([searchPath], {
          queryParams: { obj: JSON.stringify(obj) },
        });

      } else if (link.type === 'event' && link.params && link.params.eventName) {
        // 支持配置event 
        if (link.params.eventType === 'submitClick') {
          this.eventService.emit([link.params.eventName], link.params.eventValue);
        } else {
          this.eventService.emit([link.params.eventName], JSON.stringify(link.params));
        }


      } else if (link.type === 'sharePublish') {
        this.share(link);
      } else if (link.type === 'phone') {
        this.call(link)
      } else if (link.type === 'copy') {

        if (link.params) {
          let copyText = link.params.copyText;
          if (link.params.copyText2) {
            copyText += link.params.copyText2;
          }
          this.shareService.copyUrl(copyText);
        }
      } else if (link.type === 'closeModal') {
        try {
          const modal = this.modalController.getTop();
          if (modal !== undefined) {
            (await modal).dismiss('success');
          }
        } catch (error) {
        }
      } else if (link.type === 'onlyBack') {
        localStorage.setItem("needRefresh", "true");
        this.appGlobalService.popTarget();
        this.appGlobalService.goBack();
      } else if (link.type === 'onlyRefresh') {
        this.appGlobalService.reloadCurrentPage();
      } else if (link.type === 'privacy') {
        this.showPrivacyModal(link);
      } else if (link.type === 'clickTabById') {
        // 用于点击指定了tabId的选项卡
        if (link.params && link.params.tabId) {
          const id = link.params.tabId;
          if (document.getElementById(id)) {
            document.getElementById(id).click();
          }
        }
      }
    } catch (error) {

    }
  }

  async showRecommenTip(tmpTagData) {
    const modal = await this.modalController.create({
      showBackdrop: true,
      cssClass: 'recommend-modal',
      component: RecommendModalComponent,
      componentProps: { tipData: tmpTagData },
      leaveAnimation: ModalFromCenterLeave,
      enterAnimation: ModalFromCenterEnter
    });
    await modal.present();
    await modal.onDidDismiss().then((res) => {
      this.appGlobalService.popTarget();
      this.appGlobalService.goBack();
    });
  }
  async presentAlertDialogConfirm(thisTagData) {
    try {
      const modal = await this.modalController.create({
        showBackdrop: true,
        cssClass: 'recommend-modal',
        animated: false,
        component: NewInquiryPageModalComponent,
        componentProps: { tagData: thisTagData.data }
      });
      await modal.present();
      await modal.onDidDismiss().then((res) => {

      });
    } catch (error) {
    }
  }

  async showRecommenMessageVip(vipData) {
    const modal = await this.modalController.create({
      showBackdrop: true,
      cssClass: 'recommend-modal-auto-heigth',
      component: RecommendModalComponent,
      componentProps: { vipData },
      leaveAnimation: ModalFromCenterLeave,
      enterAnimation: ModalFromCenterEnter
    });
    await modal.present();
    const modalData = await modal.onDidDismiss();
  }


  //2023.12.26 for android
  async showPrivacyModal(tagData) {
    const modal = await this.modalController.create({
      showBackdrop: true,
      cssClass: 'auto-modal',
      component: UrlComponent,
      componentProps: { tagData },
      leaveAnimation: ModalFromCenterLeave,
      enterAnimation: ModalFromCenterEnter
    });
    await modal.present();
    const modalData = await modal.onDidDismiss();
  }




  /** 统一的拨打客服方法 */

  async call(data) {
    console.log(' 拨打客服 ', data);
    // 联系人
    if (data.name === undefined && data.params && data.params.name !== undefined) {
      data.name = data.params.name;
    }
    // 电话
    if (data.phone === undefined && data.params && data.params.phone !== undefined) {
      data.phone = data.params.phone;
    }
    let message = !isNullOrUndefined(data.name) ? data.name + ' ' + data.phone : data.phone;
    message = !isNullOrUndefined(data.title) ? (data.title + '<br>' + message) : message;
    const alert = await this.alertController.create({
      header: '',
      subHeader: '',
      message,
      buttons: [{
        text: '取消',
        role: 'cancel',
        cssClass: 'secondary',
        handler: (blah) => {
          console.log('取消');
        }
      }, {
        text: '拨打',
        cssClass: 'LJ',
        handler: () => {
          this.http.changeCallNumber(data.phone);
          if (data.submit) {
            const params1 = {
              id: data.submit.id,
              content: data.submit.content,
              sessionId: localStorage.getItem('sessionId')
            };
            this.http.post("application/submit", params1, res1 => {
              if (data.submitAction && data.submitAction === 'clickCount' && data.label) {
                if (typeof (data.label) === 'string' && data.label === '电话') {
                  data.label = 1;
                } else {
                  data.label++;
                }

              }
              // this.appGlobalService.consoleLog('submit', res1);
            });
          }
        }
      }]
    });
    await alert.present();
  }
  share(link) {
    // console.log('share --> page', link);
    const params = {
      sessionId: localStorage.getItem("sessionId"),
      pageId: link.target,
      params: link.params
    };
    this.http.post('application/page', params, res => {
      // console.log(JSON.parse(res.script));
      const fullObject = JSON.parse(res.script).views[0].tags[0];
      if (fullObject.type) {
        this.shareData = JSON.parse(res.script).views[0].tags[0];
      } else {
        this.shareData = JSON.parse(res.script).views[0].tags[0].data;
      }
      // console.log(this.shareData);
      this.presentModal();
    });
  }

  // 分享弹框
  async presentModal() {

    const css = localStorage.getItem('client') === 'APP' ? 'sharePage' : 'sharePageMin'
    const modal = await this.modalController.create({
      showBackdrop: true,
      cssClass: css,
      backdropDismiss: true,
      component: SharePageComponent,
      componentProps: { tagData: this.shareData }
    });
    await modal.present();
    // 监听销毁的事件
    const modalData = await modal.onDidDismiss(); // 获取关闭传回的值
    console.log(modalData);
  }


  getAndroidMobileStoreDetailByType() {

    const userAgent = window.navigator.userAgent.toLowerCase();
    // 荣耀手机




  }





  isMatchUserAgent(subjectModels) {
    const userAgent = navigator.userAgent.toLowerCase(); // 转换为小写以提高匹配效率  
    for (const model of subjectModels) {
      if (userAgent.includes(model.toLowerCase())) { // 使用toLowerCase()确保大小写不敏感  
        return true;
      }
    }
    return false;
  }


  getAndroidAppStoreH5Url(customType) {
    var resultUrl = 'https://sj.qq.com/myapp/detail.htm?apkName=com.laijian.customer'; // 蜂喔商户
    if (customType === 'fw') {
      resultUrl = 'https://a.app.qq.com/o/simple.jsp?pkgname=com.laijian.merchant';
    }
    var sUserAgent = window.navigator.userAgent.toLowerCase();
    var isHuawei = sUserAgent.match(/huawei/i);
    var isHonor = sUserAgent.match(/honor/i);
    // var isOppo = this.isMatchUserAgent(this.oppoModels);
    var isVivo = this.isMatchUserAgent(this.vivoModels);
    // var isXiaomi = this.isMatchUserAgent(this.xiaomiModels);
    // var isMeizu = this.isMatchUserAgent(this.meizuModels);
    if (isHuawei) {
      if (customType === 'fw') {
        resultUrl = 'https://url.cloud.huawei.com/s39RKzT3uU';
      } else {
        resultUrl = 'https://url.cloud.huawei.com/s39QRMB0WY';
      }
    } else if (isHonor) {
      if (customType === 'fw') {
        resultUrl = 'https://appmarket-h5.cloud.honor.com/h5/share/latest/index.html?shareId=1816410857157029888';
      } else {
        resultUrl = 'https://appmarket-h5.cloud.honor.com/h5/share/latest/index.html?shareId=1824339372365049856';
      }

    } else if (isVivo) {
      if (customType === 'fw') {
        resultUrl = 'http://h5.appstore.vivo.com.cn/#/details?app_id=3059339&app_pos=1&source=5&appId=3059339&frompage=searchResultApp&listpos=1';
      } else {
        resultUrl = 'http://h5.appstore.vivo.com.cn/#/details?app_id=3059844&app_pos=1&source=5&appId=3059844&frompage=associateApp&listpos=1';
      }
    }
    return resultUrl;
    // else if (isXiaomi) { 小米正在维护中
    //   fwURL = "http://app.xiaomi.com/detail/1318864";
    // }
    //  else if (isMeizu) { 魅族不支持暂时使用应用宝
    //   fwURL = "https://app.meizu.com/apps/public/detail?package_name=com.laijian.merchant#"
    // }
    // window.open(fwURL, '_system');
    // window.location.href = fwURL;
  }


  openApp(customType?) {
    const that = this;
    if (customType !== undefined) {
      // 2024.08.28 add by andrew.wen
      const resultUrl = this.getAndroidAppStoreH5Url(customType);
      if (customType === 'fw') {
        // H5 专用
        if (this.isWithinQQ() || this.isWithinWechat()) { // 2023.11.29 如果h5是在QQ或者微信中打开则不允许用open因为QQ和wechat会阻止弹窗
          window.location.href = resultUrl;
        } else {
          setTimeout(() => {
            window.open(resultUrl, '_system');
          }, 200);
          setTimeout(() => {
            window.open('fw://', '_system');
          }, 100);
        }
      } else if (customType === 'fwsh') {
        // H5
        if (this.isWithinQQ() || this.isWithinWechat()) { // 2023.11.29 如果h5是在QQ或者微信中打开则不允许用open因为QQ和wechat会阻止弹窗
          window.location.href = resultUrl;
        } else {
          setTimeout(() => {
            window.open(resultUrl, '_system');
          }, 200);
          setTimeout(() => {
            window.open('fwsh://', '_system');
          }, 100);
        }
      }
    } else {
      if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
        const loadDateTime: any = new Date();
        window.setTimeout(function () {
          const timeOutDateTime: any = new Date();
          if (timeOutDateTime - loadDateTime < 5000) {
            if (that.appGlobalService.clientType === 'js') {
              that.iab.create('https://a.app.qq.com/o/simple.jsp?pkgname=com.laijian.merchant', '_system');
            } else if (that.appGlobalService.clientType === 'lj') {
              that.iab.create('https://a.app.qq.com/o/simple.jsp?pkgname=com.laijian.customer', '_system');
            }
          } else {
            window.close();
          }
        }, 25);
        if (this.appGlobalService.clientType === 'js') {
          // APP
          if (localStorage.getItem('platform') === 'ios') {
            this.iab.create('fw://', '_system')
          } else {
            // H5
            location.href = 'fw://';
          }
        } else if (this.appGlobalService.clientType === 'lj') {
          if (localStorage.getItem('platform') === 'ios') {
            this.iab.create('fwsh://', '_system')
          } else {
            // H5
            location.href = 'fwsh://';
          }
        }
      } else if (navigator.userAgent.match(/android/i)) {
        const loadDateTime: any = new Date();
        try {
          const that = this;
          this.platform.ready().then(() => {
            // 只有手机端才会发起 修复H5bug
            if (localStorage.getItem('client') !== 'BROWSER' && this.platform.is('android')) {
              this.appVersion.getAppName().then((value: any) => {
                console.log(value);
                if (value === 'false') {
                  if (that.appGlobalService.clientType === 'js') {
                    that.iab.create('https://a.app.qq.com/o/simple.jsp?pkgname=com.laijian.merchant', '_system');

                  } else if (that.appGlobalService.clientType === 'lj') {
                    that.iab.create('https://a.app.qq.com/o/simple.jsp?pkgname=com.laijian.customer', '_system');
                  }
                }
              });
            } else {
              if (that.appGlobalService.clientType === 'js') {
                that.iab.create('https://a.app.qq.com/o/simple.jsp?pkgname=com.laijian.merchant', '_system');

              } else if (that.appGlobalService.clientType === 'lj') {
                that.iab.create('https://a.app.qq.com/o/simple.jsp?pkgname=com.laijian.customer', '_system');
              }
            }
          });
        } catch (error) {
        }
      }
    }
  }

  isWithinQQ() { // 是否是在手机版 QQ 打开H5连接
    return window.navigator.userAgent.toLowerCase().match(/qqtheme/i) !== null;
  }

  isWithinWechat() { // 是否是在手机版 微信 打开H5连接
    return window.navigator.userAgent.toLowerCase().match(/micromessenger/i) !== null;
  }


  getPostData(url, data, callFunction?) {
    let result: any; // 下载文件大小
    try {

      const xhr = new XMLHttpRequest();
      xhr.open('POST', url, true);
      xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      xhr.onreadystatechange = () => {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            result = xhr.responseText;
            callFunction(result);
          }
        }
      };
      xhr.send(data);
    } catch (error) {
      console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + '  error=	   ', error);
      callFunction(result);
    }
  }


  jsongetPostData(url, data, callFunction?) {
    let result: any; // 下载文件大小  
    try {
      const xhr = new XMLHttpRequest();
      xhr.open('POST', url, true);
      xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
      xhr.onreadystatechange = () => {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            result = xhr.responseText;
            callFunction(JSON.parse(result));
          } else {
            // 处理非200状态码，例如打印错误信息或调用错误处理函数  
            console.error(`Request failed with status ${xhr.status}: ${xhr.statusText}`);
            callFunction(null); // 或者传递错误信息  
          }
        }
      };
      xhr.send(JSON.stringify(data)); // 将data对象转换为JSON字符串  
    } catch (error) {
      console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + '  error=	   ', error);
      callFunction(result); // 在发生错误时调用回调函数，可能传递错误信息或null  
    }
  }




  getGetData(url, callFunction) {
    let result: any; // 下载文件大小
    try {
      const xhr = new XMLHttpRequest();
      xhr.open('GET', url, true);
      xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      xhr.onreadystatechange = () => {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            result = xhr.responseText;
            callFunction(result);
          }
        }
      };
      xhr.send();
    } catch (error) {
      console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + '  error=	   ', error);
      callFunction(result);
    }
  }


  // getFileDownloadTime(downloadUrl, callFunction?) {
  //   let time = 0;
  //   try {
  //     let fileSize; // 下载文件大小
  //     const xhr = new XMLHttpRequest();
  //     xhr.open('HEAD', downloadUrl, true);
  //     xhr.onreadystatechange = () => {
  //       if (xhr.readyState === 4) {
  //         if (xhr.status === 200) {
  //           fileSize = xhr.getResponseHeader('Content-Length');
  //           time = fileSize / 10000000;
  //           // callFunction((Math.ceil(time)));
  //         }
  //       }
  //     };
  //     xhr.send();
  //   } catch (error) {
  //     console.log('下载文件大小获取错误');
  //     callFunction(0);
  //   }
  // }

  toLogin(pageParams, title?, callbackFunc?: Function) {

    // 只有手机端才会发起极光认证
    if (!this.platform.is('mobileweb') && (this.platform.is('ios') || this.platform.is('android'))) {
      let p: any = {}
      Object.keys(pageParams.params).forEach(element => {
        if (element !== 'passwordLogin' && element !== 'oneLogin') {
          p[element] = pageParams.params[element]
        }
      });
      pageParams.params.oneLogin.params = p;
      const params = {
        sessionId: localStorage.getItem("sessionId"),
        pageId: pageParams.params.oneLogin.target,
        params: pageParams.params.oneLogin.params
      };
      this.jVerificationLogin(params, '', '', (msg) => {
        // 其他登录
        if (window['otherButton'] !== null && window['otherButton'] !== undefined) {
          const link = window['otherButton'];
          this.openPage(link, title, callbackFunc);
          window['otherButton'] = null;
        } else if (window['wxlinkButton'] !== null && window['wxlinkButton'] !== undefined) {
          const link = window['wxlinkButton'];
          this.shareService.gotoAutoLoginWithWechatOpenId(this.appGlobalService.clientType === 'js' ? 2 : 1, (res) => {
            if (res && res.isLogin !== undefined && res.isLogin) {
              let tempParam = JSON.parse(JSON.stringify(this.appGlobalService.loginRes));
              if (link.params) {
                Object.assign(tempParam.params, link.params);
              }
              // 接口还未返回该参数故用默认值
              this.processLoginData(tempParam, tempParam.data.account, tempParam.params);
            } else if (res && res.isLogin !== undefined && !res.isLogin) {
              console.log('还未绑定!');
              if (link) {
                // 跳转到普通登录页面跳转
                this.openPage(link);
              }
            }
          });
          window['wxlinkButton'] = null;
        } else {
          if (msg === 6002) { // 用户主动取消登录

          } else {
            this.normalLogin(pageParams, title, callbackFunc);
          }
        }

      });

    } else {
      this.normalLogin(pageParams, title, callbackFunc);
    }
  }

  normalLogin(pageParams, title?, callbackFunc?: Function) {
    let p: any = {}
    Object.keys(pageParams.params).forEach(element => {
      if (element !== 'passwordLogin' && element !== 'oneLogin') {

        p[element] = pageParams.params[element]
      }
    });
    pageParams.params.passwordLogin.params = p;

    this.openPage(pageParams.params.passwordLogin, title, callbackFunc);
  }
  public jVerificationLogin(params, getPhoneSubmitId0, loginSubmitId0, callBackFunction) {
    this.http.post('application/page', params, res => {
      const loginData = JSON.parse(res.script);
      const getPhoneSubmitId = loginData.data.preloadSubmit.id;
      const loginSubmitId = loginData.data.button[0].submit.id; // button[0] 表示本机号码一键登录按钮  button[1] 表示其他手机号码登录
      this.appGlobalService.jVerificationAuth((msg) => {
        // 走原来的登陆流程
        if (msg === null) {
          callBackFunction(); // 2024.04.14 fixed bug 避免安卓插件初始化不成功跳转不到普通的登录页面
        } else { // 极光登录
          const resultObj = JSON.parse(msg);
          // code: 返回码，6000代表loginToken获取成功，6001代表loginToken获取失败，其他返回码详见描述
          // content：返回码的解释信息，若获取成功，内容信息代表loginToken。
          // operator：成功时为对应运营商，CM代表中国移动，CU代表中国联通，CT代表中国电信。失败时可能为null
          if (resultObj && resultObj.code === 6000) {
            // 与后台联调submit接口
            const params1 = {
              id: loginSubmitId,
              content: { token: resultObj.content },
              sessionId: localStorage.getItem('sessionId')
            };

            // 1.9.15 后台传参 有变动
            if (loginData.data.button && loginData.data.button[0] && loginData.data.button[0].submit) {
              loginData.data.button[0].submit.content['token'] = params1.content['token'];
              params1.content = loginData.data.button[0].submit.content;
            }
            // 2024.09.19 huawei
            if (localStorage.getItem('huawei')) {
              Object.assign(params1.content, { amobile: 'huawei' });
            }
            this.http.post("application/submit", params1, res1 => {
              if (res1.success) {
                // 登录成功
                this.processLoginData(res1, res1.data.account ? res1.data.account : '', params1);
              } else {
                this.appGlobalService.showToast(res1.message, 2000, "middle");
              }
            });
          } else {
            // 极光的错误信息
            // this.appGlobalService.showToast(resultObj.content, 2000, "middle");
            // 走原来的登陆流程
            // if(resultObj.code === 6002){
            callBackFunction(resultObj.code);
            // }

          }
        }
      }, loginData);
    });
  }
  public async processLoginData(res: any, mobile: any, params) {
    try {

      // 删除已经注册的刷新event
      this.eventService.eventEmit.removeAllListeners("clearlistTagRefreshTime");
      // 处理 员工 当前定位城市
      if (res.data.position) {
        this.setPxwCityPosition(res.data.position);
      }
      // 处理登录账号信息
      if (res.data.user_id) {
        localStorage.setItem("userId", res.data.user_id);
        localStorage.setItem("loginAccount", mobile);
        this.platform.ready().then(() => {
          // 只有手机端才会发起极光s设置别名
          if (localStorage.getItem('client') !== 'BROWSER' && (this.platform.is('ios') || this.platform.is('android'))) {
            this.appGlobalService.initUmengEventWithParameters("enter_app_with_loginAccount_event");
            this.jPush
              .setAlias({
                sequence: 1,
                alias: this.appGlobalService.pushAlias + mobile
              })
              .then(
                result => {
                  const sequence = result.sequence;
                  const alias = result.alias;
                  console.log("设置别名成功：" + alias);
                },
                error => {
                  const sequence = error.sequence;
                  const errorCode = error.code;
                  console.log("设置别名失败：" + errorCode);
                }
              );
          }
        });
        this.http.get(
          "message/userinfo/im/" + res.data.user_id,
          response => {
            const data = response.data;
            if (res.data.user_id.includes('random')) {
              data.nickname = '访客';
            }
            localStorage.setItem('currentWorkMobile', data.work_mobile);
            // 2024.08.02 联调接口返回参数
            if (res.data.shopGoodsCartCount) {
              // tslint:disable-next-line:no-string-literal
              data['shopGoodsCartCount'] = res.data.shopGoodsCartCount;
            }
            this.indexedDBService.putByKeyCallbak(data, res.data.user_id, "user", () => {
              if (res.data.shopGoodsCartCount) {
                this.chatService.setCartItemCount(res.data.shopGoodsCartCount);
              }
            });
            localStorage.setItem('currentNickName', data.nickname);

          },
          error => {
            console.log("msg-----> error:" + JSON.stringify(error));
          }
        );
        if (this.chatService.ws) {
          this.chatService.connectting(localStorage.getItem("loginAccount"), true, (eData) => {
            console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + '  ws.connectting   ', eData);
          });
        }
        if (this.appGlobalService.clientType === 'pxw') {
          localStorage.setItem('startRefreshTimerTag', '1');
          this.eventService.eventEmit.emit("startRefreshTimer");
        }
      }

      // 登录成功后发现 alert 2s后跳转
      if (res.data.alert) {
        setTimeout(() => {
          const link = {
            params: res.data.alert.params,
            target: res.data.alert.target,
            type: 'pageModal'
          };
          this.openPage(link);
        }, 2000);
      }


      localStorage.setItem("loginStatus", "true");
      localStorage.setItem("needRefreshTab1", "true");
      localStorage.setItem("needRefreshTab2", "true");
      localStorage.setItem("needRefreshTab3", "true");
      localStorage.setItem("needRefreshTab4", "true");
      localStorage.setItem("needRefreshTab5", "true");


      if (localStorage.getItem("useTarget") === "true") {
        const cityId = JSON.parse(localStorage.getItem("position"))
          ? JSON.parse(localStorage.getItem("position")).code
          : 4403;
        const pageParams = {
          pageId: res.target,
          params: {
            code: cityId
          },
          sessionId: localStorage.getItem("sessionId")
        };
        this.appGlobalService.goToForward(pageParams);
        localStorage.removeItem("useTarget");
      } else {
        const skip = res.skip;
        if (skip && skip === 1) {
          // "是否跳转页面 0不跳/1跳"

          const pageParams = {
            pageId: res.target,
            params: res.params,
            sessionId: localStorage.getItem("sessionId")
          };
          if (res.params && res.params && res.params.pageType) {
            pageParams['type'] = 'modal';
            pageParams['target'] = pageParams.pageId;
            this.openPage(pageParams);
          } else {
            this.appGlobalService.goToForward(pageParams);
          }
        } else if (skip === 0) {
          let tmpParams = res.params;
          if (localStorage.getItem('back_target') !== null) {
            tmpParams = params.content;
          }
          const pageParams = {
            pageId: res.target,
            params: tmpParams,
            sessionId: localStorage.getItem("sessionId")
          };
          this.appGlobalService.goToForward(pageParams);
        } else if (localStorage.getItem("isDetailPage") && skip === 0 && res.params.page_name === undefined) {
          localStorage.setItem("needRefresh", "true");
          this.appGlobalService.popTarget();
          this.appGlobalService.goBack();

        } else if (skip && skip === 4) { // 跳转到模态窗口
          // "是否跳转页面 0不跳/1跳"
          const link = {
            pageId: res.target,
            params: res.params,
            sessionId: localStorage.getItem("sessionId")
            , type: 'modal'
          };
          this.openPage(link);
        } else {
          localStorage.setItem("needRefresh", "true");
          this.appGlobalService.goBack();
        }
      }

      // // 关闭 已经打开的modal
      // const modal = this.modalController.getTop();
      // if (modal) {
      //     (await modal).dismiss('success');
      // }
    } catch (error) {

    }
  }

  // 处理 员工 当前定位城市
  setPxwCityPosition(positionInfo) {
    if (this.appGlobalService.clientType === 'pxw') {
      // 如果有第一次城市信息，firstPostion === {}，存firstPostion
      const firstPostion = localStorage.getItem('firstPostion');
      if (!firstPostion) {
        localStorage.setItem('firstPostion', JSON.stringify(positionInfo));
        localStorage.setItem('position', JSON.stringify(positionInfo));
        this.eventService.eventEmit.emit('getPointByName', JSON.stringify(positionInfo));

      }
    }
  }


  wxAuth(tagData) {
    this.shareService.gotoAutoLoginWithWechatOpenId(this.appGlobalService.clientType === 'js' ? 2 : 1, (res) => {
      if (res && res.isLogin !== undefined && res.isLogin) {
        let tempParam = JSON.parse(JSON.stringify(this.appGlobalService.loginRes));
        // 蜂喔用户与蜂喔商户登录都要经过此方法来获取openid
        if (tagData.wxLink
          && tagData.wxLink.params
          && tagData.wxLink.params.page_name !== undefined) {
          tempParam.target = tagData.wxLink.params.page_name;
          Object.assign(tempParam.params, tagData.wxLink.params);
        } else if (tagData.data && tagData.data.wxLink
          && tagData.data.wxLink.params
          && tagData.data.wxLink.params.page_name !== undefined) {
          tempParam.target = tagData.data.wxLink.params.page_name;
          Object.assign(tempParam.params, tagData.data.wxLink.params);
        }
        this.processLoginData(tempParam, tempParam.data.account, tempParam.params);
        // 接口还未返回该参数故用默认值
      } else if (res && res.isLogin !== undefined && !res.isLogin) {
        console.log('还未绑定!');
        // 跳转到普通登录页面
        if (tagData.wxLink) {
          this.openPage(tagData.wxLink);
        } else if (tagData.data && tagData.data.wxLink) {
          this.openPage(tagData.data.wxLink);
        }
      }
    });

  }
  removeModeId(modalId) {
    if (this.modalIdArray && this.modalIdArray.length > 0) {
      const index = this.modalIdArray.findIndex((v) => (v === modalId));
      if (index > -1) {
        this.modalIdArray.splice(index, 1);
      }
    }

  }
  // 生成弹窗id
  addModeId(id?) {
    if (id) {
      this.modalIdArray.push(id);
      return id;
    } else {
      const modalId = new Date().getTime().toString();
      this.modalIdArray.push(modalId);
      return modalId;
    }


  }
  // 关闭第几个弹窗 从index 0 开始
  // 配置下一个link.params.closeModalIndex = 0 1 2 todo:有需求在实现
  closeModal(index) {
    if (this.modalIdArray && this.modalIdArray.length > 0) {
      this.modalController.dismiss({}, '', this.modalIdArray[index]);
    }
  }
  // 关闭指定id弹窗 todo:有需求在实现
  closeModalWithId(id) {
    if (id) {
      this.modalController.dismiss({}, '', id);
      this.removeModeId(id);
    } else {
      this.modalController.dismiss();
    }
  }
  // 关闭所有弹窗 
  // 配置下一个link.params.closeAllModal = "true" 
  // 或者 在common-submit-btn 配置 submit.content.closeAllModal = "true" 
  closeAllModal() {
    if (this.modalIdArray && this.modalIdArray.length > 0) {
      const tempArr = JSON.parse(JSON.stringify(this.modalIdArray));
      for (let index = 0; index < tempArr.length; index++) {
        if (document.getElementById(tempArr[index]) !== null) {
          this.modalController.dismiss({}, "", tempArr[index]);
        }

      }
    }
  }


  // 2023年9月4日新增初始化极光推送、一键登录通用方法
  initJiguangPushAndAddListener() {

    if ((typeof JGVerificationPlugin) !== 'undefined' && this.appGlobalService.clientType === 'lj') {
      JGVerificationPlugin.init(function (msg) {
        const tmpMsg = JSON.parse(msg);
        // 8000 代表初始化成功
        if (msg && tmpMsg.code === 8000) {
          console.log('jG初始化成功...')
        } else {
          console.log('jG初始化失败...')
        }
      });
    }
    try {
      if (this.jPush) {
        this.jPush.init();
      }
      this.addListener();
    } catch (e) {
      console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + '  	catch(e)   ', e);
    }
  }
  addListener() {
    document.addEventListener(
      "jpush.openNotification",
      this.onOpenNotification,
      false
    );
    document.addEventListener(
      "jpush.receiveNotification",
      this.onReceiveNotification,
      false
    );
    document.addEventListener(
      "jpush.backgroundNotification",
      this.onBackgroundNotification,
      false
    );
    document.addEventListener(
      "jpush.receiveMessage",
      this.onReceiveMessage,
      false
    );
  }
  // 启动或唤醒应用程序时会触发该事件
  onOpenNotification = (event) => {
    console.log("open notification: \n" + JSON.stringify(event));
    setTimeout(() => {
      this.managePushMessage(event);
    }, 3);

  }
  // 前台收到推送
  onReceiveNotification = (event) => {
    console.log("onReceiveNotification :\n" + JSON.stringify(event));
    setTimeout(() => {
      this.clearBadage();
    }, 5000);
  }
  // 应用程序处于后台时收到推送会触发该事件
  onBackgroundNotification = (event) => {
    console.log("onBackgroundNotification :\n" + JSON.stringify(event));
    setTimeout(() => {
      this.managePushMessage(event);
    }, 1);
  }
  // 收到应用内消息时触发这个事件, 推荐使用事件的方式传递，但同时保留了 receiveMessageIniOSCallback 的回调函数，兼容以前的代码。
  onReceiveMessage = (event) => {
    try {
      const message = event.content;
    } catch (exception) { }
  }



  clearBadage() {
    this.jPush.resetBadge();
    if (localStorage.getItem("platform") === "ios") {
      // iOS
      // {
      //   "aps":{
      //       "alert":"你好铺铺旺",
      //       "badge":4,
      //       "sound":""
      //   },
      //   "extras":{
      //       "messageType":"1",
      //       "params":"{tabIndex:4}",
      //       "target":"58801",
      //       "url":"http://www.baidu.com"
      //   },
      // }
      this.jPush.setApplicationIconBadgeNumber(0);
    } else {
      // Android
      // {
      //     "isTrusted":false,
      //     "title":"蜂喔",
      //     "sound":"neworder",
      //     "alert":"【深圳】的【13661656545】客户咨询【装修】【美容美发54㎡】,请【深圳芈熊科技装饰有限公司】及时处理",
      //     "extras":{
      //         "cn.jpush.android.ALERT_TYPE":"7",
      //         "cn.jpush.android.NOTIFICATION_ID":529597311,
      //         "cn.jpush.android.MSG_ID":"38280835468139451",
      //         "cn.jpush.android.ALERT":"【深圳】的【13661656545】客户咨询【装修】【美容美发54㎡】,请【深圳芈熊科技装饰有限公司】及时处理",
      //         "messageSkip":"0",
      //         "params":"",
      //         "target":"",
      //         "url":"",
      //     }
      // }
      this.jPush.clearAllNotification();
    }
  }

  // 2024.07.17 前端转换一下
  convertNotificationStringToObject(str) {

    if (typeof (str) === 'object') {
      return str;
    }
    // shop_customer_msg_id::6683970cc5636c1e7abf8dd6,aaa::6683970cc5636c1e7abf8dd6
    // 使用逗号分割字符串，得到一个数组  
    const pairs = str.split(',');
    const result = {};

    // 遍历数组，进一步分割每个元素，并将结果存入对象  
    pairs.forEach(pair => {
      const [key, value] = pair.split(':');
      result[key] = value;
    });

    return result;
  }

  isNotOnlyDigits(str) {
    // 使用正则表达式检查字符串是否不是只包含数字  
    return !/^\d+$/.test(str);
  }


  gotoPageByTarget(extras, extrasParam) {
    const params = {
      pageId: extras.target,
      params: this.convertNotificationStringToObject(extrasParam),
      sessionId: localStorage.getItem("sessionId"),
    };

    this.appGlobalService.goToForward(params);
  }

  gotoPage(extras, extrasParam) {
    if (this.isNotOnlyDigits(extras.target)) {
      this.http.get('application/pageTypeToId/' + localStorage.getItem('sessionId') + '/' + extras.target, res => {
        extras.target = res;
        this.gotoPageByTarget(extras, extrasParam)
      });
    } else {
      this.gotoPageByTarget(extras, extrasParam);

    }
  }



  managePushMessage(obj, isGotoPage?) {

    console.log("obj~~~~~", JSON.parse(JSON.stringify(obj)));
    const extras = obj.extras;
    console.log("extras~~~~~", extras);
    let title = '';
    if (obj.aps !== undefined) {
      title = obj.aps.alert;
    } else {
      title = obj.title;
    }

    // 2024.07.16 防止安卓收不到
    if (extras.messageSkip !== undefined) {
      extras.messageType = extras.messageSkip;
    }

    console.log("aps~~~~~", title);
    if (extras.messageType === "0") {
      setTimeout(() => {
        this.clearBadage();
      }, 5000);
      return;
    } else if (
      extras.messageType === "1" &&
      extras.target &&
      extras.target.length > 0
    ) {
      console.log("link~~~~~");

      let extrasParam = {};
      if (localStorage.getItem('platform') === 'ios') {
        extrasParam = extras.params;
      } else {
        extrasParam = extras["cn.jpush.android.EXTRA"].params;
      }

      this.gotoPage(extras, extrasParam);

    } else if (
      extras.messageType === "3" &&
      extras.target &&
      extras.target.length > 0
    ) {
      console.log("link~~~~~");

      let extrasParam = {};
      if (localStorage.getItem('platform') === 'ios') {
        extrasParam = extras.params;
      } else {
        extrasParam = extras["cn.jpush.android.EXTRA"].params;
      }

      this.gotoPage(extras, extrasParam);
      this.needRefreshTab();
    } else if (extras.messageType === "2" && extras.url && extras.url.length) {
      this.appGlobalService.openUrl(title, extras.url);
    }
    setTimeout(() => {
      this.clearBadage();
    }, 5000);
  }
  needRefreshTab() {
    setTimeout(() => {
      const tab = localStorage.getItem('tab');
      if (tab && tab.indexOf("tab") > -1) {
        const tabIndex = tab.substring(tab.length - 1);
        console.log("needRefreshTab" + tabIndex);
        localStorage.setItem('needRefreshTab' + tabIndex, 'true');
        this.eventService.eventEmit.emit(tab, '1');
        console.log('submit eventEmit--->' + tab);
      }
    }, 1000);
  }
  showSettingLocation() {
    this.showPopover('permission',
      {
        title: '开启定位',
        content: '我们需要获取该权限，才能为您提供查看周边数据的服务', settingType: 'application_details'
      });
  }

  showSettingCamera() {
    this.showPopover('permission',
      {
        title: '开启相机',
        content: '我们需要获取相机权限才能继续为您服务',
        settingType: 'application_details'
      });
  }
  showSettingVideo() {
    this.showPopover('permission',
      {
        title: '开启相机和麦克风',
        content: '我们需要获取相机和麦克风权限才能继续为您服务',
        settingType: 'application_details'
      });
  }

  showSettingAlbum() {
    this.showPopover('permission',
      {
        title: '开启相册',
        content: '我们需要获取相册权限才能继续为您服务',
        settingType: 'application_details'
      });
  }
  // that.appGlobalService.showPopover('permission', {title: '开启定位', content: '我们需要获取该权限，才能为您提供查看周边数据的服务', settingType: 'application_details'});
  async showPopover(type, data) {
    const modal = await this.modalController.create({
      showBackdrop: true,
      cssClass: 'custom-popover',
      backdropDismiss: false,
      component: CustomPopoverComponent,
      componentProps: { tagData: data, type }
    });
    await modal.present();
    // 监听销毁的事件
    const modalData = await modal.onDidDismiss().then((data) => {
      console.log(data, "showPopover dimiss");
    }); // 获取关闭传回的值
  }
  getPageTagDataWithPageRes(res: any, callback: Function) {
    console.log('global service page data------->');
    const pageData = JSON.parse(res.script);
    const tags = pageData.views === undefined ? pageData.tags : pageData.views[0].tags;
    const tagData = tags.length > 0 ? tags[0].data : {};
    callback(tagData);
  }

  getTagDataByStyleNameWithPageRes(styleName: any, name: any, res: any, callback: Function) {
    console.log(' getTagDataByStyleNameWithPageRes page data------->');
    const pageData = JSON.parse(res.script);
    const tags = pageData.views === undefined ? pageData.tags : pageData.views[0].tags;
    let tagData;
    if (tags.length > 0) {
      for (let index = 0; index < tags.length; index++) {
        const element = tags[index];
        if (element.style === styleName && element.name === name) {
          tagData = element;
          callback(tagData);
          break;
        }
      }
    }


  }

}
